//
//  LVColletionViewHelper.m
//  Live
//
//  Created by Pie on 16/7/2.
//  Copyright © 2016年 Heller. All rights reserved.
//

#import "LVColletionViewHelper.h"
#import "MJRefreshFooter.h"
#import "MJRefreshHeader.h"
#import "UIView+MJExtension.h"
#import "UIScrollView+MJRefresh.h"

@implementation LVColletionViewHelper

- (instancetype)initWithCollectionView:(UICollectionView *)collectionView
{
    if((self = [super init]) != nil) {
        self.collectionView = collectionView;
    }
    return self;
}

- (void)setCollectionView:(UICollectionView *)collectionView
{
    if (_collectionView != collectionView) {
        _collectionView = nil;
        _collectionView = collectionView;
        
        self.currentScrollView = collectionView;
    }
}

#pragma mark - LVDatasourceHelperProtocol

- (void)reloadData
{
    [self.collectionView reloadData];
}

- (void)loadMore
{
    if (self.isLoading) {
        return;
    }
    
    [super loadMore];

    if (self.collectionView) {
        if(self.delegate && [self.delegate respondsToSelector:@selector(load:collectionView:)]) {
            [self.delegate load:self.currentPage collectionView:self.collectionView];
        }
    }
}

- (void)reload
{
    if (self.isLoading) {
        return;
    }
    
    [super reload];

    [self.collectionView.mj_footer setHidden:YES];
    if(self.showLoading && ![[self.collectionView mj_header] isRefreshing] && self.hintView == nil)
    {
        if(self.delayLoadingInterval > 0.0){
            [self performSelector:@selector(delayLoading) withObject:nil afterDelay:self.delayLoadingInterval];
        }else {
            [self delayLoading];
        }
    }
    
    if (self.collectionView) {
        if(self.delegate && [self.delegate respondsToSelector:@selector(load:collectionView:)]) {
            [self.delegate load:self.currentPage collectionView:self.collectionView];
        }
    }
    
    self.loadOnce = YES;
}

- (void)reloadNotPullView
{
    [super reloadNotPullView];
    
    if (self.collectionView) {
        if(self.delegate && [self.delegate respondsToSelector:@selector(load:collectionView:)]) {
            [self.delegate load:self.currentPage collectionView:self.collectionView];
        }
    }
}

- (void)reloadAndAutoPullView
{
    [super reloadAndAutoPullView];
}

@end
